## Replication code for Usher and Kim-Leffingwell. 2024. "How Loud Does the Watchdog Bark? 
## A Reconsideration of Losing Local Journalism, News Nonprofits, and Political Corruption" 
## International Journal of Press/Politics. 

ijppdat <- readRDS("ijppdat.rds")

# Figure 1 Trend in PPCs across judicial districts
library(ggplot2)

ggplot(ijppdat, aes(inn_trend, corruption, color = factor(treated))) +
  stat_summary(geom = 'line') +
  geom_vline(xintercept = 0) +
  theme_bw() + 
  labs(x="Time since the year of INN introduction (t=0)", y="Prosecutions for Public Corruption") +
  theme(legend.position = "none") + scale_color_manual(values=c("gray60","gray30"))+
  annotate("text",x=2,y=15, label="Districts with INN",size=3,color="gray30")+
  annotate("text",x=2,y=7, label="Districts without INN",size=3,color="gray50") +
  scale_x_continuous(breaks=c(-5:5))

ggsave("DDplot.png",width=6,height=4)


# Table 1 Newspaper Employment, Circulation, and Prosecutions for Public Corruption.
## Models 1-3: time-series-cross-section data 

tab1dat1 <- readRDS("tab1dat1.rds")
tab1dat2 <- readRDS("tab1dat2.rds")

library(plm)
tab1model1 <- plm(corruption~log(employment+1)+log(lag.emp+1)+log(pop)+inn_hist+
                    log(gdp_pc)+(timetodesp), data=tab1dat1, 
                  model="within", effect="twoways",
                  index=c("attorneydistrict","year"))
tab1model2 <- plm(corruption~log(lag.emp+1)+log(lag.emp2+1)+log(pop)+inn_hist+
                    log(gdp_pc)+(timetodesp), data=tab1dat1, 
                  model="within", effect="twoways",
                  index=c("attorneydistrict","year"))
tab1model3 <- plm(corruption~log(lag.emp2+1)+log(lag.emp3+1)+log(pop)+inn_hist+
                    log(gdp_pc)+(timetodesp), data=tab1dat1, 
                  model="within", effect="twoways",
                  index=c("attorneydistrict","year"))

## Models 4 and 5: aggregated data
tab1model4<-lm(corruption~log(circulation)+log(population.y)+inn_hist+
              log(gdp_pc)+(timetodesp), data=tab1dat2)
tab1model5<-plm(corruption~log(circulation)+log(population.y)+inn_hist+
               log(gdp_pc)+(timetodesp), data=tab1dat2,
             model="within", effect="twoways",
             index=c("attorneydistrict","year"))

stargazer::stargazer(tab1model1,tab1model2,tab1model3,tab1model4, tab1model5,
                     type="text", df=F,
                     covariate.labels = c("Newspaper Employment (t=0, log)",
                                          "Newspaper Employment (t-1, log)",
                                          "Newspaper Employment (t-2, log)",
                                          "Newspaper Employment (t-3, log)",
                                          "Population (log)",
                                          "Circulation (t=0, log)",
                                          "Population (log)",
                                          "INN members (t-1)",
                                          "GDP per capita (log)",
                                          "Court efficiency"), 
                     omit="Constant")


# Table 2 INN Membership and Prosecutions for Public Corruption.
ijppdat2 <- readRDS("ijppdat2.rds")

tab2model1 <- lm((corruption) ~ lag.inn , 
                data = ijppdat2)
tab2model2 <-  plm((corruption) ~ lag.inn + log(pop) + log(gdp_pc)+lag.emp+
                     timetodesp, 
                   data = ijppdat2,model="within", effect="twoways",
                   index=c("attorneydistrict","year"))

## cross-section model
temp1 <- aggregate(cbind(pop,gdp_pc,timetodesp,corruption,employment, inn_hist)~attorneydistrict, mean, data=ijppdat)
temp2 <- aggregate(INN~attorneydistrict, sum, data=ijppdat)
temp3 <- cbind(temp1,temp2)

tab2model3 <- lm((corruption) ~ inn_hist + log(pop) + log(gdp_pc)+timetodesp+log(employment+1), 
                data = temp3)

library("lmtest")
library("sandwich")
cov1          <- vcovHC(tab2model1, type = "HC2",cluster="attorneydistrict")
robust_se1    <- sqrt(diag(cov1))

stargazer::stargazer(tab2model1,tab2model2,tab2model3,type="text",df=F,
                     omit=c("attorneydistrict","Constant"), 
                     dep.var.labels = "Corruption",
                     covariate.labels = c("INN members (t-1)", "INN members (cross-section)", "Population (log)",
                                          "GDP pc (log)", "Employment (t-1)","Court efficiency", 
                                          "Employment (cross-section)", "Constant"),
                     omit.stat = c("ser","rsq","adj.rsq"),
                     se=list(robust_se1))

# Table 3 Results from Difference-in-Differences Analysis of INN Membership on Prosecutions for Public Corruption.

tab3model1 <- lm((corruption) ~ time_did*treated + log(pop) + log(gdp_pc)+timetodesp+ log(lag.emp+1), 
                data = ijppdat)
tab3model2 <- lm((corruption) ~ time_did2*treated + log(pop) + log(gdp_pc)+timetodesp+ log(lag.emp+1), 
                data = ijppdat)
tab3model3 <- lm((corruption) ~ inn_trend*treated + log(pop) + log(gdp_pc)+timetodesp+log(lag.emp+1)
                , 
                data = ijppdat)

cov4          <- vcovHC(tab3model1, type = "HC2",cluster="attorneydistrict")
robust_se4    <- sqrt(diag(cov4))

cov5          <- vcovHC(tab3model2, type = "HC2",cluster="attorneydistrict")
robust_se5    <- sqrt(diag(cov5))

cov6          <- vcovHC(tab3model3, type = "HC2",cluster="attorneydistrict")
robust_se6    <- sqrt(diag(cov6))

stargazer::stargazer(tab3model1, tab3model2, tab3model3, type="text",df=F, 
                     se=list(robust_se4,robust_se5, robust_se6),
                     keep=c("time_did","treated","pop","gdp_pc","inn_trend", "timetodesp","lag.emp","Constant"),
                     covariate.labels = c("Time (t=0)","Time (t=1)","Time Trend" ,"INN District","Population (log)",
                                          "GDP pc (log)", "Court Efficiency", "Employment (log)", 
                                          "Time (t=0)*INN District",
                                          "Time (t=1)*INN District","Time Trend*INN District","Constant"),
                     omit.stat = c("ser","rsq","adj.rsq"))


# Table 4 Funding for Nonprofit Journalism and Prosecutions for Public Corruption.
tab4dat <- readRDS("tab4dat.rds")

tab4model1 <- lm(corruption.x~log(funding), data=tab4dat)
tab4model2 <- lm(corruption.x~log(funding)+log(population.y)+log(gdp_pc.x+1)+
                        (timetodesp.x)+log(lag.emp+1)+factor(year),
                      data=tab4dat)

stargazer::stargazer(tab4model1,tab4model2, type="text", df=F,
                     dep.var.labels = "Corruption",
                     covariate.labels=c("Funding (log)", "Population (log)","GDP pc (log)",
                                        "Court Efficiency", "Employment (log, t-1)"),
                     se=list(frobust_se1rr, frobust_se2rr),
                     keep = c("funding","population.y","gdp_pc",
                              "timetodesp","lag.emp", "Constant"),
                     add.lines=list(c('Fixed effects', 'Yes','Yes')))
